<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="挂号单号" prop="registerId">
        <el-input
          v-model="queryParams.registerId"
          placeholder="请输入挂号单号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="患者id" prop="patientId">
        <el-input
          v-model="queryParams.patientId"
          placeholder="请输入患者id"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="科室id" prop="deptId">
        <el-input
          v-model="queryParams.deptId"
          placeholder="请输入科室id"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="挂号类型" prop="registerType">
        <el-select v-model="queryParams.registerType" placeholder="请选择挂号类型" clearable size="small">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item label="挂号时段" prop="registerSubsectionTime">
        <el-input
          v-model="queryParams.registerSubsectionTime"
          placeholder="请输入挂号时段"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="挂号时间" prop="registerTime">
        <el-date-picker clearable size="small"
          v-model="queryParams.registerTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择挂号时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="挂号费用" prop="registerCost">
        <el-input
          v-model="queryParams.registerCost"
          placeholder="请输入挂号费用"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>


    <el-table v-loading="loading" :data="registerList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="挂号单号" align="center" prop="registerId" />
      <el-table-column label="患者id" align="center" prop="patientId" />
      <el-table-column label="科室id" align="center" prop="deptId" />
      <el-table-column label="当前号数" align="center" prop="registerSort" />
      <el-table-column label="挂号类型" align="center" prop="registerType" />
      <el-table-column label="挂号时段" align="center" prop="registerSubsectionTime" />
      <el-table-column label="挂号费用" align="center" prop="registerCost" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:register2:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:register2:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改【请填写功能名称】对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="挂号单号
" prop="registerId">
          <el-input v-model="form.registerId" placeholder="请输入挂号单号
" />
        </el-form-item>
        <el-form-item label="患者id
" prop="patientId">
          <el-input v-model="form.patientId" placeholder="请输入患者id
" />
        </el-form-item>
        <el-form-item label="医生id
" prop="doctorId">
          <el-input v-model="form.doctorId" placeholder="请输入医生id
" />
        </el-form-item>
        <el-form-item label="科室id
" prop="deptId">
          <el-input v-model="form.deptId" placeholder="请输入科室id
" />
        </el-form-item>
        <el-form-item label="挂号类型" prop="registerType">
          <el-select v-model="form.registerType" placeholder="请选择挂号类型">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="挂号时段
" prop="registerSubsectionTime">
          <el-input v-model="form.registerSubsectionTime" placeholder="请输入挂号时段
" />
        </el-form-item>
        <el-form-item label="挂号时间
" prop="registerTime">
          <el-date-picker clearable size="small"
            v-model="form.registerTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择挂号时间
">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="流水id" prop="turnoverId">
          <el-input v-model="form.turnoverId" placeholder="请输入流水id" />
        </el-form-item>
        <el-form-item label="挂号费用" prop="registerCost">
          <el-input v-model="form.registerCost" placeholder="请输入挂号费用" />
        </el-form-item>
        <el-form-item label="收费状态 0 未收费 1已收费">
          <el-radio-group v-model="form.costStatus">
            <el-radio label="1">请选择字典生成</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="就诊状态 0 未就诊 1已就诊">
          <el-radio-group v-model="form.outpatientStatus">
            <el-radio label="1">请选择字典生成</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listRegister, getRegister, delRegister, addRegister, updateRegister, exportRegister } from "@/api/syl_DZ/D/OutpatientPatient2/register";

export default {
  name: "Register",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      registerList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        registerId: null,
        patientId: null,
        doctorId: null,
        deptId: null,
        registerType: null,
        registerSubsectionTime: null,
        registerTime: null,
        turnoverId: null,
        registerCost: null,
        costStatus: null,
        outpatientStatus: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        registerId: [
          { required: true, message: "挂号单号不能为空", trigger: "blur" }
        ],
        patientId: [
          { required: true, message: "患者id不能为空", trigger: "blur" }
        ],
        deptId: [
          { required: true, message: "科室id不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询【请填写功能名称】列表 */
    getList() {
      this.loading = true;
      listRegister(this.queryParams).then(response => {
        this.registerList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        registerId: null,
        patientId: null,
        doctorId: null,
        deptId: null,
        registerSort: null,
        registerType: null,
        registerSubsectionTime: null,
        registerTime: null,
        turnoverId: null,
        registerCost: null,
        costStatus: "0",
        outpatientStatus: "0",
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.registerSort)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加【请填写功能名称】";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const registerSort = row.registerSort || this.ids
      getRegister(registerSort).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改【请填写功能名称】";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.registerSort != null) {
            updateRegister(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addRegister(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const registerSorts = row.registerSort || this.ids;
      this.$confirm('是否确认删除【请填写功能名称】编号为"' + registerSorts + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delRegister(registerSorts);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有【请填写功能名称】数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportRegister(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
    }
  }
};
</script>
